//package com.cenntro.oss.common.db2;
//
//import javax.sql.DataSource;
//
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import com.alibaba.druid.pool.DruidDataSource;
//
//
//@Configuration
//@MapperScan(basePackages = "com.cenntro.oss.mycat", sqlSessionTemplateRef  = "mycatSqlSessionTemplate")
//public class MycatDataSourceConfig {
//
//    @Bean(name = "mycatDataSource")
////    @ConfigurationProperties(prefix = "spring.datasource.mycat")
//    @Primary
//    public DataSource getDataSource() {
//    	
//    	DataSource db = mycatDataSourceProperties().initializeDataSourceBuilder().build();
//    	DruidDataSource ds = (DruidDataSource)db;
//    	ds.setInitialSize(30);
//    	ds.setMaxActive(100);
//    	return db;
//      //  return DataSourceBuilder.create().build();
//    }
//
//    @Bean
//    @Primary
//    //获取Environment属性，Environment从.properties文件获取配置信息
//    @ConfigurationProperties("spring.datasource.mycat")
//    public DataSourceProperties mycatDataSourceProperties() {
//     return new DataSourceProperties();
//    }
//    @Bean(name = "mycatSqlSessionFactory")
//    @Primary
//    public SqlSessionFactory getSqlSessionFactory(@Qualifier("mycatDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        
//        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/**/*.xml"));
//        return bean.getObject();
//    }
//
//    @Bean(name = "mycatTransactionManager")
//    @Primary
//    public DataSourceTransactionManager getTransactionManager(@Qualifier("mycatDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "mycatSqlSessionTemplate")
//    @Primary
//    public SqlSessionTemplate getSqlSessionTemplate(@Qualifier("mycatSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//}